package com.baor.service.impl;
import com.baor.dao.BackDao;
import com.baor.service.BackService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.Map;

@Service
public class BackServiceImpl implements BackService {
    @Autowired
    private BackDao backDao;
    @Override
    public AjaxResult<?> backList(Map<String, Object> params) {
        params.put("pageIndex", (int)params.get("pageSize") * ((int)(params.get("pageIndex")) - 1));
        params.put("pageSize", params.get("pageSize"));
        Map<String,Object> res = new HashMap<>();
        res.put("backList", backDao.backList(params));
        res.put("pageCount", backDao.pageCount(params));
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> backNotes(Map<String, Object> params) {
        return AjaxResult.success(backDao.backNotes(params));
    }

    @Override
    public AjaxResult<?> updateBackNotes(Map<String, Object> params) {
        if (backDao.updateBackNotes(params)>0){
            return AjaxResult.success("更新成功");
        }else {
            return AjaxResult.error("更新失败");
        }
    }

    @Override
    public AjaxResult<?> backInfo(Map<String, Object> params) {
        return AjaxResult.success(backDao.backInfo(params));
    }

    @Override
    public AjaxResult<?> addBack(Map<String, Object> params) {
        if (this.backDao.addBack(params)>0){
            return AjaxResult.success("添加成功");
        }else {
            return AjaxResult.error("添加失败");
        }
    }
}
